#include "userskeleton.h"

QVector<UserSkeleton::UserJoint> UserSkeleton::staticJoints;

UserSkeleton::UserSkeleton() {
}

UserSkeleton::~UserSkeleton() {
}

bool UserSkeleton::hasUserPosition(int userJoint) const {
    return positions.contains(userJoint);
}

QVector3D UserSkeleton::userPosition(int userJoint) const {
    if (hasUserPosition(userJoint)) {
        return positions.find(userJoint).value();
    } else {
        return QVector3D();
    }
}

QPointF UserSkeleton::userProjection(int userJoint) const {
    if (hasUserPosition(userJoint)) {
        return projections.find(userJoint).value();
    } else {
        return QPointF();
    }
}

void UserSkeleton::setUserPosition(int userJoint, QVector3D position, QPointF projection) {
    positions.insert(userJoint, position);
    projections.insert(userJoint, projection);
}

bool UserSkeleton::hasUserOrientation(int userJoint) const {
    return orientations.contains(userJoint);
}

QMatrix3x3 UserSkeleton::userOrientation(int userJoint) const {
    if (hasUserOrientation(userJoint)) {
        return orientations.find(userJoint).value();
    } else {
        return QMatrix3x3();
    }
}

void UserSkeleton::setUserOrientation(int userJoint, QMatrix3x3 position) {
    orientations.insert(userJoint, position);
}

float UserSkeleton::userPositionConfidence(int userJoint) const {
    if (positionConfidence.contains(userJoint)) {
        return positionConfidence.find(userJoint).value();
    } else {
        return 0;
    }
}

void UserSkeleton::setUserPositionConfidence(int userJoint, float conf) {
    positionConfidence.insert(userJoint, conf);
}

float UserSkeleton::userOrientationConfidence(int userJoint) const {
    if (orientationConfidence.contains(userJoint)) {
        return orientationConfidence.find(userJoint).value();
    } else {
        return 0;
    }
}

void UserSkeleton::setUserOrientationConfidence(int userJoint, float conf) {
    orientationConfidence.insert(userJoint, conf);
}

QVector<UserSkeleton::UserJoint> UserSkeleton::allJoints() {
    if (staticJoints.empty()) {
        staticJoints.append(Head);
        staticJoints.append(Neck);
        staticJoints.append(Torso);
        staticJoints.append(Waist);
        staticJoints.append(LeftCollar);
        staticJoints.append(LeftShoulder);
        staticJoints.append(LeftElbow);
        staticJoints.append(LeftWrist);
        staticJoints.append(LeftHand);
        staticJoints.append(LeftFingerTip);
        staticJoints.append(RightCollar);
        staticJoints.append(RightShoulder);
        staticJoints.append(RightElbow);
        staticJoints.append(RightWrist);
        staticJoints.append(RightHand);
        staticJoints.append(RightFingertip);
        staticJoints.append(LeftHip);
        staticJoints.append(LeftKnee);
        staticJoints.append(LeftAnkle);
        staticJoints.append(LeftFoot);
        staticJoints.append(RightHip);
        staticJoints.append(RightKnee);
        staticJoints.append(RightAnkle);
        staticJoints.append(RightFoot);
    }
    return staticJoints;
}
